import matplotlib.pyplot as plt
import numpy as np
import sys
import sys

dicts = {}
maxtime = 0

with open(sys.argv[1], 'r') as f:
	for line in f.readlines():
		ComponentName, StatisticName, StatisticSubId, StatisticType, SimTime, Rank, Sumu64, SumSQu64, Countu64, Minu64, Maxu64 = line.split(', ')
		#time = int(SimTime)/1000000
		time = int(SimTime)
		maxtime = time
		value = int(Sumu64) 
		factor = ComponentName+"_"+StatisticName+"_"+StatisticSubId
		if factor not in dicts.keys():
			dicts[factor] = [[time],[value]]
		else:
			dicts[factor][0].append(time)
			dicts[factor][1].append(value) 
#print(dicts)
#xticks = [-79, 279, 579, 879, 1179, 1479]
#xll = ['0', '300000000', '600000000', '900000000', '1200000000', '1500000000']
total_num = 10
for factor in dicts.keys():
	total_num -= 1
	if total_num < 0:
		break
	xpoints = dicts[factor][0]
	ypoints = dicts[factor][1]
	for i in np.arange(len(ypoints)-1,0,-1):
		ypoints[i] -= ypoints[i-1] 
	#ypoints[0] = 0
	#print(ypoints)
	plt.figure(figsize=(10, 6))
	plt.title(factor)
	plt.xlabel('Simulation time (us)')
	plt.ylabel('Accumulated value')
	#plt.xticks(xticks, xll)
	plt.plot(xpoints, ypoints)
	#plt.bar(xpoints, ypoints, width=1)
	plt.savefig('results/%s_plot.png' % (factor), dpi=300)
	plt.close()
	#break
	#plt.plot(xpoints, ypoints)
	#plt.savefig('results/%s_line.png' % factor)
	#plt.clf()
